const app = getApp()
Page({
  data: {
    bank:{
      money:0
    },
    input_money:0,
    disabled:false
  },
  //生命周期函数--监听页面显示
  onShow: function () {
    app.loginState(()=>{
      this.getApi();
    },true)
  },
  getApi:function () {
    app.api().Get("api/v1/ais/user/balance",(rel) => {
      if(200 == rel.code){
        this.setData({
          bank:rel.data
        }) 
      }
		})
  },
  onInputs: function (e) {
    var input_money = e.detail.value > 0 ? e.detail.value:0;
    if(input_money > this.data.bank.money){
      input_money = this.data.bank.money;
      app.wxAlert('最大提现金额'+this.data.bank.money);
    }
    this.setData({
      input_money:input_money
    })
  },
  setPass: function () {
		wx.navigateTo({
      url: '/packageHelper/pages/safepasspord',
    })
  },
  /**
   * 申请提现
   */
  onSubmit: function (e) {
    var data = e.detail.value;
    //安全密码
    if (app.util().isNull(data.safepassword)) {
      app.wxAlert('安全密码必须填写');
    }else if (app.util().isNull(data.money)) {
      app.wxAlert('转出金额必须填写');
    } else {
      if (parseFloat(data.money) > this.data.money) {
        app.wxAlert('转出金额超出钱包余额');
      }else{
        this.setData({
          disabled:true
        })
        setTimeout(()=>{
          this.setData({
            disabled:false
          })
        },2000)
        app.api().Post('api/v1/ais/user/cash', {
          money: data.money,
          safepassword: data.safepassword
        },(rel)=>{
          if (rel.code == 200) {
            app.wxAlert(rel.msg,()=>{
              wx.navigateBack({delta:1})
            });
          }
        })
      }
    }
  }
})